import tensorflow as tf

# 定义tensor
a=tf.constant(2)
b=tf.constant(3)
c=tf.constant(5)

# tensor的运算操作
# 注意  tensor 同样支持python操作符 + - * /
add=tf.add(a,b)
sub=tf.subtract(a,b)
mul=tf.multiply(a,b)
div=tf.divide(a,b)

# 获取值
print('add=',add.numpy())
print('sub=',sub.numpy())
print('mul=',mul.numpy())
print('div=',div.numpy())

# 更多操作
mean=tf.reduce_mean([a,b,c])
sum=tf.reduce_sum([a,b,c])

# 获取tensor值
print('mean=',mean.numpy())
print('sum=',sum.numpy())

# 矩阵相乘
matrix1=tf.constant([[1.,2.],[3.,4.]])
matrix2=tf.constant([[5.,6.],[7.,8.]])

product=tf.matmul(matrix1,matrix2)

# 展示tensor
print(product)

# 把tensor转换成numpy
product.numpy()